import type { MaFormItem } from "@mineadmin/form";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as getEnterpriseList } from "@/plugins/ai-warning/organization/api/rdOrganizeEnterprise.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  // 编辑模式：只允许修改归属企业和备注
  if (formType === "edit") {
    return [
      {
        label: "归属企业",
        prop: "enterprise_id",
        render: () => MaRemoteSelect,
        renderProps: {
          api: getEnterpriseList,
          axiosConfig: {
            autoRequest: true,
            params: {
              page: 1,
              pageSize: 1000,
            },
          },
          dataHandle: (response: any) => {
            if (response.code === 200 && response.data && response.data.list) {
              return response.data.list.map((enterprise: any) => ({
                label: enterprise.name,
                value: enterprise.id,
              }));
            }
            return [];
          },
          placeholder: "请选择归属企业",
          filterable: true,
          clearable: true,
        },
        itemProps: {
          rules: [{ required: true, message: "请选择归属企业" }],
        },
      },
      {
        label: "备注",
        prop: "remark",
        render: "input",
        renderProps: {
          type: "textarea",
          rows: 4,
          placeholder: "请输入备注信息",
          maxlength: 500,
          showWordLimit: true,
        },
        itemProps: {
          rules: [{ required: true, message: "请输入备注信息" }],
        },
      },
    ];
  }

  // 新增模式：返回空数组或完整表单
  return [];
}
